package com.ztstudy.poi.Java_Map_demos.jihe.collection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class CollectionExercise {
    public static void main(String[] args)
    {
        Dog dog1 = new Dog("小花", 3);
        Dog dog2 = new Dog("小龙", 3);
        Dog dog3 = new Dog("小黄", 3);
        List list = new ArrayList();
        list.add(dog1);
        list.add(dog2);
        list.add(dog3);
        //迭代器遍历
        System.out.println("迭代器遍历");
        Iterator it = list.iterator();
        while (it.hasNext()) {
            Object next =  it.next();
            System.out.println(next);
        }
        //增强for循环遍历
        System.out.println("增强for循环遍历");
        for (Object o : list){
            System.out.println(o);
        }

    }
}

class Dog{
    private String name;
    private int age;

    public Dog(String name, int age)
    {
        this.name = name;
        this.age = age;
    }

    public String getName()
    {
        return name;
    }

    public int getAge()
    {
        return age;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public void setAge(int age)
    {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
